package test.view;

import com.google.inject.Inject;
import ms.aurora.forms.Form;
import ms.aurora.forms.FormHandler;
import test.model.DefaultModel;
import test.presenter.DefaultCallback;
import test.presenter.DefaultPresenter;

import javax.swing.*;
import java.awt.*;

public class DefaultView extends JPanel implements DefaultPresenter.MyView {
    private static final long serialVersionUID = -31187623896194569L;
    private final DefaultCallback defaultCallback;
    private JLabel helloLabel;
    private JButton closeButton;

    @Inject
    public DefaultView(DefaultCallback defaultCallback) {
        this.defaultCallback = defaultCallback;
        initComponents();
    }

    public void initComponents() {
        Form<DefaultModel> form = new Form<DefaultModel>(DefaultModel.class,
                new DefaultModel());
        form.setFormHandler(new FormHandler<DefaultModel>() {
            @Override
            public void onCancel(DefaultModel model) {
                JOptionPane.showMessageDialog(null, "Too bad!");
            }

            @Override
            public void onSubmit(DefaultModel model) {
                JOptionPane.showMessageDialog(null, "Hi " + model);
            }
        });
        add(form);
    }

    @Override
    public Component asComponent() {
        return this;
    }

}
